home *** CD-ROM | disk | FTP | other *** search
- {
- Ripples generator, by Maple Leaf, Nov 1996
- ---------------------------------------------------------------------------
- This could be used as an anti-publicity program for TP's floating point
- emulation... What would I do if I hadn't the assembler to program with ?
- Oh, shit...
- ----------------------------------------------------------------------------
- Do whatever you want with this crappy code, but if you use parts of it in
- your production(s), please send some greets to Maple Leaf (Gruian Radu).
- Thanx.
- }
-
- uses alloc, files, bitmap;
-
- var vScr, sqrTab : word;
- Img : pointer;
- Pal : array[byte] of record r,g,b:byte end;
-
- Wave : array [0..199] of word; { 200 words are quite enough ... }
-
- procedure InitVideo;near;assembler;
- asm
- mov ax,13h
- int 10h { init video mode }
- mov dx,3c8h
- mov al,0
- out dx,al
- inc dx
- mov cx,768
- mov si,offset pal
- rep outsb { set palette }
- end;
-
- procedure vWait;near;assembler;
- asm
- mov dx,3DAh
- @1: in al,dx
- test al,8
- jne @1
- @2: in al,dx
- test al,8
- je @2
- end;
-
- procedure ShowVScreen;near;assembler;
- asm
- push ds
- push es
- mov cx,16000
- mov ax,0A000h
- mov es,ax
- mov di,0
- mov si,di
- mov ds,VScr
- cld
- db 66h; rep movsw
- pop es
- pop ds
- end;
-
- procedure freeAll;
- begin
- free(img);
- hfree(vScr);
- hfree(sqrTab);
- end;
-
- procedure InitData;
- begin
- vScr:=halloc(64000);
- sqrTab:=halloc(161*101*2); { [0..160,0..100] of word }
- Img:=LoadPCX(paramstr(1),@pal);
- if (Img=nil) or (vScr=0) or (sqrTab=0) then begin
- freeAll;
- asm mov ax,3; int 10h end;
- writeln('Not enough memory');
- halt
- end;
- end;
-
- procedure PreCalc; { this shit will take some time... }
- var x,y,k:word;
- begin
- for x:=0 to 160 do
- for y:=0 to 100 do begin
- k:=trunc( sqrt( sqr(x) + sqr(y) ) );
- memw[sqrTab:(y*161+x)*2]:=k;
- end;
- end;
-
- var ang:word;
-
- procedure UpdateWave;
- const Amplitude : word = 10;
- Frequency : word = 15; { ripples/(160 pixels) }
- var k:word;
- begin
- inc(ang,1);
- for k:=0 to 199 do
- Wave[k]:=trunc(Amplitude*sin(Frequency*(k-ang)*pi/180));
- end;
-
- procedure DrawRipples;
- var x,y,offs,offs2,dist:integer;
- byt:byte;
- xx,yy,alt:integer;
- procedure stosb;
- begin
- mem[vScr:offs]:=byt;
- inc(offs);
- end;
- begin
- offs:=0;
- for y:=0 {!!!} to 199 do begin { fuck ! }
- for x:=0 {!!!} to 319 do begin
-
- xx:=abs(x-160);
- yy:=abs(y-100);
-
- dist:=memw[sqrTab:2*(yy*161+xx)]; { compute distance to origin (160,100) }
- alt:=Wave[dist]; { altitude of this dot }
-
- xx:=x;
- yy:=y+alt;
- if yy>199 then yy:=yy-200;
- if yy<0 then yy:=yy+200;
- offs2:=yy*320+xx;
-
- byt:=mem[seg(img^):word(offs2)];
- stosb;
- end;
- end;
- end;
-
- procedure DoIt;
- begin
- Precalc;
- repeat
- UpdateWave;
- DrawRipples;
- vWait;
- ShowVScreen;{}
- until port[$60]=1;
- end;
-
- begin
- if paramcount=0 then begin
- writeln('RIPPLES FileName.PCX');
- halt
- end;
- InitData;
- InitVideo;
- DoIt;
- asm mov ax,3; int 10h end;
- freeAll;
- end.
-